package com.example.yuejian.yuejian.model;

import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.ClubClass;
import com.example.yuejian.yuejian.bean.ClubInfo;
import com.example.yuejian.yuejian.bean.ClubList;
import com.example.yuejian.yuejian.bean.ClubVideo;
import com.example.yuejian.yuejian.bean.Masters;
import com.example.yuejian.yuejian.service.ClubService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/10.
 */

public class ClubModel {
    private Retrofit retrofit;

    public ClubModel() {
        retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Contants.BASE_URL)
                .build();
    }
    public void clubList(int type, final ModleListListener listListener)
    {
        ClubService service=retrofit.create(ClubService.class);
        Call<List<ClubList>>call=service.clubtypelist(type);
        call.enqueue(new Callback<List<ClubList>>() {
            @Override
            public void onResponse(Call<List<ClubList>> call, Response<List<ClubList>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<ClubList>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    public void ClubDetail(String clubid, final ModleListener listener)
    {
       ClubService service=retrofit.create(ClubService.class);
        Call<ClubInfo>call=service.clubdetail(clubid);
        call.enqueue(new Callback<ClubInfo>() {
            @Override
            public void onResponse(Call<ClubInfo> call, Response<ClubInfo> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<ClubInfo> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
    public void CoachList(String club_id,final ModleListListener listListener)
    {
        ClubService service=retrofit.create(ClubService.class);
        Call<List<Masters>>call=service.clubcoachList(club_id);
        call.enqueue(new Callback<List<Masters>>() {
            @Override
            public void onResponse(Call<List<Masters>> call, Response<List<Masters>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Masters>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    public  void ClassList(String club_id,final ModleListListener listListener)
    {
       ClubService service=retrofit.create(ClubService.class);
        Call<List<ClubClass>>call=service.ClubClass(club_id);
        call.enqueue(new Callback<List<ClubClass>>() {
            @Override
            public void onResponse(Call<List<ClubClass>> call, Response<List<ClubClass>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<ClubClass>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    public void ClubVideo(String clubid,final ModleListListener listListener)
    {
        ClubService service=retrofit.create(ClubService.class);
        Call<List<ClubVideo>>call=service.Clubvideo(clubid);
        call.enqueue(new Callback<List<ClubVideo>>() {
            @Override
            public void onResponse(Call<List<ClubVideo>> call, Response<List<ClubVideo>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<ClubVideo>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
}
